package com.sinopec.handdevice.view

import android.graphics.Color
import android.os.Bundle
import android.widget.TextView
import com.alibaba.android.arouter.facade.annotation.Route
import com.gyf.immersionbar.ImmersionBar
import com.sinopec.basemodule.adapter.CommonAdapter
import com.sinopec.basemodule.adapter.CustomViewHolder
import com.sinopec.basemodule.base.BaseActivity
import com.sinopec.basemodule.base.BasePresenter
import com.sinopec.basemodule.base.CustomToolbar
import com.sinopec.basemodule.utils.ARouterManagerUtils
import com.sinopec.handdevice.R
import kotlinx.android.synthetic.main.activity_normal_code_list.*

/**
 * @author lwj
 * @ClassName: NormalCodeListActivity
 * @Description:已读有效编码查看界面
 */
@Route(path = ARouterManagerUtils.GOTO_MAIN_NORMAL_CODE_LIST_ACTIVITY)
class NormalCodeListActivity : BaseActivity<BasePresenter>() {

    private var datas: ArrayList<String> = arrayListOf()
    private var adapter: CommonAdapter<String>? = null

    private val mPalletCodes by lazy {
        intent.getStringArrayListExtra("palletCodes") ?: ArrayList<String>()
    }

    override fun getContentView(): Int {
        return R.layout.activity_normal_code_list
    }

    override fun initView(savedInstanceState: Bundle?) {
        //总编码数
        tv_totalCount.text = mPalletCodes.size.toString()

        datas.clear()
        datas.addAll(mPalletCodes)
        adapter = object :
            CommonAdapter<String>(mContext, R.layout.item_normal_code, datas) {
            override fun convert(
                holder: CustomViewHolder,
                str: String,
                position: Int,
            ) {
                val itemView = holder.itemView
                //序号
                val tv_serial_number = holder.getView<TextView>(R.id.tv_serial_number)
                tv_serial_number.text = (position + 1).toString()
                //托盘编码
                val tv_palletCode = holder.getView<TextView>(R.id.tv_palletCode)
                tv_palletCode.text = str

                if (position % 2 == 0) {
                    itemView.setBackgroundColor(Color.parseColor("#ffffff"))
                } else {
                    itemView.setBackgroundColor(Color.parseColor("#F5F8FA"))
                }
            }
        }
        rv_list.adapter = adapter
    }

    override fun setStatusBar() {
        ImmersionBar.with(this).statusBarDarkFont(true).init()
    }


    override fun initEvent() {
        super.initEvent()
    }

    override fun configToolbar(rToolbar: CustomToolbar) {
        //配置标题
        rToolbar.setTitle("已读有效编码")
    }
}